#ifndef TRAJET_H
#define TRAJET_H

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <list>
#include <time.h>
#include "capitaine.h"
#include "second.h"
#include "matelot.h"
#include "navire.h"
#include "port.h"

using namespace std;


class Trajet
{

    friend bool operator < (const Trajet & t1, const Trajet & t2)
    {
        if(t1.timeDepart.tm_year < t2.timeDepart.tm_year)
        {
            return true;
        }
        else if(t1.timeDepart.tm_year+2000 == t2.timeDepart.tm_year+2000)
        {
            if(t1.timeDepart.tm_mon < t2.timeDepart.tm_mon)
            {
                return true;
            }
            else if(t1.timeDepart.tm_mon == t2.timeDepart.tm_mon)
            {
                if(t1.timeDepart.tm_mday < t2.timeDepart.tm_mday)
                {
                    return true;
                }
                else if(t1.timeDepart.tm_mday == t2.timeDepart.tm_mday)
                {
                    if(t1.timeDepart.tm_hour < t2.timeDepart.tm_hour)
                    {
                        return true;
                    }
                    else if(t1.timeDepart.tm_hour == t2.timeDepart.tm_hour)
                    {
                        if(t1.timeDepart.tm_min <= t2.timeDepart.tm_min)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }
        return false;
    }


private:
    int idTrajet;
    Port* portDepart;
    Port* portArrivee;
    Navire * navireAffecte;
    float prix;
    list<Capitaine*> listCapitainesAffectes;
    list<Second*> listSecondsAffectes;
    list<Matelot*> listMatelotsAffectes;
    struct tm timeDepart, timeArrivee;
public:
    Trajet();
    Trajet(int idTrajet, Port* depart, Port* arrivee, struct tm timeD, struct tm timeA, float px);
    Trajet(int idTrajet, Port* depart, Port* arrivee, struct tm timeD, struct tm timeA, float px, Navire * nav);
    Trajet(int idTrajet, Port* depart, Port* arrivee, struct tm timeD, struct tm timeA, float px, Navire * nav, list<Capitaine*> lc, list<Second*> ls, list<Matelot*> lm);
    ~Trajet();

    // GETTERS
    int getIdTrajet();
    float getPrix();
    list<Capitaine*> getListCapitainesAffectes();
    list<Second*> getListSecondsAffectes();
    list<Matelot*> getListMatelotsAffectes();
    Port* getPortDepart();
    Port* getPortArrivee();
    Navire* getNavireAffecte();
    struct tm getTimeDepart();
    struct tm getTimeArrivee();



    // SETTERS
    void setIdTrajet(int id);
    void setPrix(float p);
    /*void setListCapitainesAffectes();
    void setListSecondsAffectes();
    void setListMatelotsAffectes();*/
    void setPortDepart(Port* depart);
    void setPortArrivee(Port* arrivee);
    void setNavireAffecte(Navire * n);
    void setTimeDepart(struct tm timeD);
    void setTimeArrivee(struct tm timeA);


    string AfficherTimeDepart();
    string AfficherTimeArrivee();
    string AfficherDateDepart();
    string AfficherDateArrivee();
    string AfficherHeureDepart();
    string AfficherHeureArrivee();

    // OPERATIONS SUR LES LISTES
    void AjouterCapitaine(Capitaine * cap);
    void RetirerCapitaine(Capitaine * cap);
    string AfficherListCapitaines();

    void AjouterSecond(Second * sec);
    void RetirerSecond(Second * sec);
    string AfficherListSeconds();

    void AjouterMatelot(Matelot * mat);
    void RetirerMatelot(Matelot * mat);
    string AfficherListMatelots();


    bool isTrajetCourant();
    bool isAnterieur(const Trajet & t1, const Trajet & t2);

};

#endif // TRAJET_H
